#ifndef __FAT16_H__
#define __FAT16_H__

#include <tipos.h>
#include <device.h>

#define MAX_OPEN_FILE 32

//Boot sector para fat16
typedef struct fat16_BS_str {
	unsigned char 		bootjmp[3];
	unsigned char 		oem_name[8];
	unsigned short 	    bytes_por_sector;
	unsigned char		sectores_por_cluster;
	unsigned short		sectores_reservados;
	unsigned char		tablas_fat;
	unsigned short		entradas_del_directorio;
	unsigned short		sectores_totales;
	unsigned char		media_type;
	unsigned short		sectores_por_tabla;
	unsigned short		sectores_por_pista;
	unsigned short		numero_de_cabezales;
	unsigned int 		sectores_ocultos;
	unsigned int 		cantidad_sectores_32;
	unsigned char		id_volumen;
	unsigned char		reserved1;
	unsigned char		firma_de_boot;
	unsigned int		volumen_id;
	unsigned char		volumen_label[11];
	unsigned char		fat_type_label[8];

}__attribute__((packed)) fat16_BS;


//estructura para una entrada en el directorio de archivos
typedef struct {
	char nombre[8];
	char extension[3];
	unsigned char attr;
	char _reserved[10];
	unsigned short time;
	unsigned short date;
	unsigned short cluster;
	unsigned size;
} __attribute__((packed)) fat16_direntry;

//atributos para las entrada del directorio de paginas
enum fat16_attributes {
	READ_ONLY=1,
	HIDDEN=2,
	SYSTEM=4,
	VOLUME_LABEL=8,
	DIRECTORY=16,
	ARCHIVE=32,
	WEIRD0=64, // dunno the meaning for these (LFN ?)
	WEIRD1=128, //ditto here.
};

/* Class fat16 */
typedef struct str_fat16 {
	blockdev *dev;
	
	unsigned short	bytes_por_sector;
	unsigned short	bytes_por_cluster;
	unsigned char	sectores_por_cluster;
	unsigned short	sectores_reservados;
	unsigned char	tablas_fat;
	unsigned short	entradas_del_directorio;
	unsigned short	sectores_totales;
	unsigned short	sectores_por_tabla;
	
	unsigned short	inicio_del_directorio;
	
} fat16;

void fat16_init(void);

chardev* fat16_open(fat16* this, const char* filename, uint_32 flags);

void fat16_create(fat16* this, blockdev* dev);

#endif
